﻿using System.Collections.Generic;
using System.Text.Json;

namespace ZYing.LiquidThemeEngine.Locales;

public class LocaleDictionary : SortedDictionary<string, string>
{
    public static LocaleDictionary Empty { get; } = new LocaleDictionary();

    internal void MergeJsonIntoDictionary(string theme, string file, JsonElement element, string path)
    {
        switch (element.ValueKind)
        {
            case JsonValueKind.Object:
                foreach (var item in element.EnumerateObject())
                {
                    var name = (path + "." + item.Name).Trim('.');
                    MergeJsonIntoDictionary(theme, file, item.Value, name);
                }
                break;
            case JsonValueKind.String:
                this[path] = element.GetString();
                break;
        }
    }
}